package com.dingxin.ship_together_api.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.util.SaResult;
import com.dingxin.ship_together_api.entity.constant.PermissionConstant;
import com.dingxin.ship_together_api.entity.vo.PageQueryVo;
import com.dingxin.ship_together_api.entity.vo.order.OrderAddVo;
import com.dingxin.ship_together_api.service.OrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Author: ctj
 * Date: 2022-09-14
 * Time: 16:51
 */
@RestController
@SaCheckLogin
@RequestMapping("order")
public class OrderController {
    @Autowired
    private OrderInfoService orderInfoService;

    @RequestMapping("add")
    @SaCheckPermission(PermissionConstant.System_OrderMng_Add)
    public SaResult add(@RequestBody @Validated OrderAddVo orderAddVo){
        return SaResult.ok().setData(orderInfoService.save(orderAddVo));
    }

    // @RequestMapping("del")
    // @SaCheckPermission(PermissionConstant.System_OrderMng_Del)
    // public SaResult del(@RequestBody OrderInfo orderInfo){
    //     if (!orderInfoService.logicDelete(orderInfo)) {
    //         return SaResult.error();
    //     }
    //     return SaResult.ok();
    // }
    //
    // @RequestMapping("mod")
    // @SaCheckPermission(PermissionConstant.System_OrderMng_Mod)
    // public SaResult mod(@RequestBody OrderInfo orderInfo){
    //     if (!orderInfoService.updateById(orderInfo)) {
    //         return SaResult.error();
    //     }
    //     return SaResult.ok();
    // }

    @RequestMapping("list")
    @SaCheckPermission(PermissionConstant.System_OrderMng_Qry)
    public SaResult list(@RequestBody PageQueryVo pageQueryVo){
        return SaResult.ok().setData(orderInfoService.selectPage(pageQueryVo));
    }
}
